export function contentsLoader ({ params, request }) {
  const url = new URL(request.url)
  const keyword = url.searchParams.get('keyword')
  const { cid } = params
  let sql = 'select * from contents'
  if (keyword) {
    sql += ' where title like @keyword order by id desc'
    return window.api.sql(sql, 'findAll', {
      keyword: `%${keyword}%`,
    })
  }
  if (cid != null) {
    sql += ` where category_id=${cid}`
  }
  sql += ' order by id desc'

  return window.api.sql(sql, 'findAll')
}
